package com.study.business.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @program: web_user
 * @author: zhang
 * @create: 2019-01-20 16:51
 **/
public class JdbcUtil {

    private static final int USER_NUM = 1000000;

    public static void add() {
        Connection con = null;
        PreparedStatement ps = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/world?useSSL=false&useUnicode=true&characterEncoding=UTF-8",
                    "root", "root");
            ps = con.prepareStatement("INSERT INTO city VALUES(null,?,?,?,?)");
            for (int i = 0; i < USER_NUM; i++) {
                ps.setObject(1, "zhangyi" + i);
                ps.setObject(2, "ABW");
                ps.setObject(3, "b" + i);
                ps.setObject(4, i);
                System.out.println(ps.executeUpdate());
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }

            }
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }

            }
        }
    }

    public static void main(String[] args) {
        add();
    }
}
